package v1beta1

import (
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
	NatReasonWaitForGuest      = "waitForGuestReady"
	NatReasonWaitForNatGateway = "waitForNatGateway"
	NatReasonCreateFailed      = "CreateFailed"
)

// NatSpec defines the desired state of nat
type NatSpec struct {
	OwnerId         string        `json:"owner_id,omitempty"`
	CloudResourceId string        `json:"cloudresource_id,omitempty"`
	ProviderRef     ProviderRef   `json:"providerRef,omitempty"`
	NatGwRef        NatGatewayRef `json:"natGwRef,omitempty"`
	//nat type：dnat、snat
	NatType string `json:"natType,omitempty"`

	//resource ip
	InternalIp string `json:"internalIp,omitempty"`
	//resource port
	InternalPort uint32 `json:"internalPort,omitempty"`
	////eport name
	//Eport    string `json:"eport,omitempty"`
	Protocol string `json:"protocol,omitempty"` //协议tcp/udp
	//Description string `json:"description,omitempty"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// +kubebuilder:resource:shortName=nat
// +kubebuilder:subresource:status

// Nat is the Schema for the nat API
type Nat struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   NatSpec   `json:"spec,omitempty"`
	Status NatStatus `json:"status,omitempty"`
}

type NatStatus struct {
	Phase          NatPhaseType `json:"phase,omitempty"`
	Info           NatRuleInfo  `json:"info,omitempty"`
	NatGatewayName string       `json:"natGatewayName,omitempty"`
	// +optional
	Conditions []Condition `json:"conditions,omitempty"`
}

type Condition struct {
	Message    string      `json:"message,omitempty"`
	UpdateTime metav1.Time `json:"updateTime,omitempty"`
	Status     string      `json:"status,omitempty"`
	Reason     string      `json:"reason,omitempty"`
}

type NatRuleInfo struct {
	NatRuleId    string `json:"natRuleId,omitempty"`
	ExternalIp   string `json:"externalIp,omitempty"`
	ExternalPort uint32 `json:"externalPort,omitempty"`
}
type NatPhaseType string

const (
	NatCreatingPhase NatPhaseType = "Creating"
	NatReadyPhase    NatPhaseType = "Ready"
	NatFailedPhase   NatPhaseType = "Failed"
	NatPendingPhase  NatPhaseType = "Pending"
)

type NatGatewayRef struct {
	Name      string `json:"name"`
	Namespace string `json:"namespace"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// NatList contains a list of nat item
type NatList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []Nat `json:"items"`
}
